
#ifndef BODECHARTVIEW_H
#define BODECHARTVIEW_H

#include <BMap>
#include <BFont>
#include <BIcon>
#include <BPointArray>
#include <BHBoxLayout>
#include <BCheckBox>
#include <BLineEdit>
#include <BTableWidget>
#include <BButtonGroup>
#include <BScrollArea>
#include <BFloatSpinBox>
#include <BDoubleSpinBox>
#include <BRealSpinBox>
#include <BSpinBox>
#include <BLongSpinBox>
#include <BLine>
#include <BLabel>

#include "ChartView.h"

class MarkChartView : public ChartView
{
	BOBJECT(MarkChartView)
public:
	MarkChartView(const BString& title = BString(), BWidget* parent = 0);
	~MarkChartView();

	bool clearMasks();

	int markCount() const;
	BRealPoint markRatio(int index) const;

protected:
	void createFileMenu();
	void createContentMenu();
	void createSettingMenu();
	void createCenterMenu();
	void freshMarkInfos();
	void freshMenu();

protected:
	void slotSeriesAttached(BObject* object, const BValue& value);
	void slotSeriesDetached(BObject* object, const BValue& value);
	void slotSeriesColorChanged(Series* series, const BValue& value);
	void slotParamsChnaged(BObject* object, const BValue& value);
	void slotSeriesButtonClicked(BButton* button, const BValue& value);
	void slotSeriesButtonFramed(BButton* button, const BValue& value);

	void slotSetAxisButtonClicked(BObject* object, const BValue& value);
	void slotContentsButtonClicked(BObject* object, const BValue& value);
	void slotDeleteButtonClicked(BObject* object, const BValue& value);
	void slotExecuteButtonClicked(BObject* object, const BValue& value);
	void slotFileCheckBoxChecked(BWidget* widget, const BValue& value);
	void slotOkButtonClicked(BObject* object, const BValue& value);
	void slotCheckButtonGroupToggled(BObject* object, const BValue& value);
	void slotContentCheckBoxChecked(BWidget* widget, const BValue& value);
	void slotSettingButtonClicked(BObject* object, const BValue& value);

	void slotTimeColorButtonClicked(BObject* object, const BValue& value);
	void slotTimeUnitEditFinished(BObject* object, const BValue& value);
	void slotTimeScaleEditFinished(BObject* object, const BValue& value);

	void slotValueColorButtonClicked(BObject* object, const BValue& value);
	void slotValueUnitEditFinished(BObject* object, const BValue& value);
	void slotValueScaleEditFinished(BObject* object, const BValue& value);

	void slotLinesWidthEditFinished(BObject* object, const BValue& value);
	void slotLinesCurveChecked(BObject* object, const BValue& value);
	void slotTextOffsetEditFinished(BObject* object, const BValue& value);
	void slotCircleRadiusEditFinished(BObject* object, const BValue& value);
	void slotDecimalsEditFinished(BObject* object, const BValue& value);

	void slotPointColorButtonClicked(BObject* object, const BValue& value);
	void slotPointSizeEditFinished(BObject* object, const BValue& value);

	void slotInsertCursorActionTriggered(BObject* object, const BValue& value);
	void slotRemoveCursorActionTriggered(BObject* object, const BValue& value);

protected:
	virtual void scrolling(Orientation orientation);

protected:
	virtual void resizeEvent(const BEvent& event);

	virtual void styleEvent(const BEvent& event);
	virtual void freshEvent(const BEvent& event);
	virtual void paintEvent(const BEvent& event);

	virtual void mouseEnterEvent(const BMouseEvent& mouseEvent);
	virtual void mouseLeaveEvent(const BMouseEvent& mouseEvent);

	virtual void mousePressEvent(const BMouseEvent& mouseEvent);
	virtual void mouseReleaseEvent(const BMouseEvent& mouseEvent);

	virtual void mouseMoveEvent(const BMouseEvent& mouseEvent);
	virtual void mouseClickEvent(const BMouseEvent& mouseEvent);

private:
	BHBoxLayout*		_buttonLayout;
	BLabel*				_indexLabel;
	BLineEdit*			_xLineEdit;
	BLineEdit*			_yLineEdit;
	BButton*			_setAxisButton;

	BButton*			_fileButton;
	BButton*			_contentButton;
	BButton*			_settingButton;

	BMenu*				_fileMenu;
	BTableWidget*		_fileTable;
	BButton*			_okButton;
	BButton*			_deleteButton;
	BButton*			_executeButton;

	BMenu*				_contentMenu;
	BTableWidget*		_contentTable;

	BMenu*				_settingMenu;
	BButton*			_timeColorButton;
	BRealSpinBox*		_timeUnitSpinBox;
	BRealSpinBox*		_timeScaleSpinBox;
	BButton*			_valueColorButton;
	BRealSpinBox*		_valueUnitSpinBox;
	BRealSpinBox*		_valueScaleSpinBox;
	BButton*			_pointColorButton;
	BSpinBox*			_linesWidthSpinBox;
	BCheckBox*			_curveCheckBox;
	BFloatSpinBox*		_circleRadiusSpinBox;
	BFloatSpinBox*		_pointSizeSpinBox;
	BLineEdit*			_textOffsetEdit;
	BSpinBox*			_decimalsSpinBox;

	BMenu*					_centerMenu;
	BAction*				_insertCursorAction;
	BAction*				_removeCursorAction;

	BMap<BString, SeriesHolder>	_seriesArray;
	BMap<BReal, BRealPoint>	_catchPointMap;
	BMap<BReal, BRealLine>	_catchLineMap;
	BArray<BColor>			_colorStore;
	BPoint					_textOffset;
	BHolder<const BStyle>	_tipsStyle;
	struct MarkInfo
	{
		bool		visible;
		BRealPoint	point;
		BRealPoint	ratio;
		BReal		time;
		BReal		value;
		BString		text;
	};
	BArray<MarkInfo>	_markInfos;
	Orientation			_hoverOrientation;
	int					_hoveredIndex;
	bool				_leftPressed;
	int					_selectedIndex;
};

#endif
